import java.util.ArrayDeque;
import java.util.Deque;

/**
 * @author 兴趣使然黄小黄
 * @version 1.0
 * 双栈模拟队列
 */
@SuppressWarnings({"all"})
public class MyQueue {

    Deque<Integer> inStack; // 入队存储栈
    Deque<Integer> outStack; // 模拟出队和peek

    public MyQueue() {
        inStack = new ArrayDeque<>();
        outStack = new ArrayDeque<>();
    }

    public void push(int x) {
        inStack.push(x);
    }

    public int pop() {
        // 如果outStack为空 则先依次出栈inStack放入outStack
        if (outStack.isEmpty()){
            while (!inStack.isEmpty()){
                outStack.push(inStack.pop());
            }
        }
        return outStack.pop();
    }

    public int peek() {
        // 如果outStack为空 则先依次出栈inStack放入outStack
        if (outStack.isEmpty()){
            while (!inStack.isEmpty()){
                outStack.push(inStack.pop());
            }
        }
        return outStack.peek();
    }

    public boolean empty() {
        return inStack.isEmpty() && outStack.isEmpty();
    }
}
